﻿using Fidely.Framework;
using Fidely.Framework.Compilation.Objects.Evaluators;
using Fidely.Framework.Compilation.Objects.Operators;
using Fidely.Framework.Compilation.Operators;

namespace Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.ViewModels
{
    public class CodeMetricsCalculationResultViewModel : CodeAnalysisResultViewModelBase<MetricValueViewModel>
    {
        private static CodeMetricsCalculationResultGridViewModel grid = new CodeMetricsCalculationResultGridViewModel();


        public CodeMetricsCalculationResultGridViewModel Grid
        {
            get
            {
                return grid;
            }
        }


        public CodeMetricsCalculationResultViewModel()
            : base(CreateCompilerSetting())
        {
        }


        private static CompilerSetting CreateCompilerSetting()
        {
            var setting = new CompilerSetting();

            setting.Evaluators.Add(new PropertyEvaluator<MetricValueViewModel>());
            setting.Evaluators.Add(new TypeConversionEvaluator());

            setting.Operators.Add(new PartialMatch<MetricValueViewModel>(":", true, OperatorIndependency.Strong, "Partial matching operator"));
            setting.Operators.Add(new PrefixSearch<MetricValueViewModel>("=:", true, OperatorIndependency.Strong, "Prefix search operator"));
            setting.Operators.Add(new SuffixSearch<MetricValueViewModel>(":=", true, OperatorIndependency.Strong, "Suffix search operator"));
            setting.Operators.Add(new Equal<MetricValueViewModel>("=", true, OperatorIndependency.Strong, "Equal operator"));
            setting.Operators.Add(new LessThan<MetricValueViewModel>("<", OperatorIndependency.Strong, "Less than operator"));
            setting.Operators.Add(new LessThanOrEqual<MetricValueViewModel>("<=", OperatorIndependency.Strong, "Less than or equal operator"));
            setting.Operators.Add(new GreaterThan<MetricValueViewModel>(">", OperatorIndependency.Strong, "Greater than operator"));
            setting.Operators.Add(new GreaterThanOrEqual<MetricValueViewModel>(">=", OperatorIndependency.Strong, "Greater than or equal operator"));
            setting.Operators.Add(new Add("+", 1, OperatorIndependency.Strong, "Add operator"));
            setting.Operators.Add(new Subtract("-", 1, OperatorIndependency.Strong, "Subtract operator"));
            setting.Operators.Add(new Multiply("*", 0, OperatorIndependency.Strong, "Multiply operator"));
            setting.Operators.Add(new Divide("/", 0, OperatorIndependency.Strong, "Divide operator"));

            return setting;
        }
    }
}
